home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2026 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie question:  Is this code OK?
  5. Date: 18 Jan 1996 15:53:12 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan18105312@g7240065.bridge.bst.bls.com>
  8. References: <4di986$fk1@pegasus.interpac.net> <30FDDAC8.D79@e-tex.com>
  9. NNTP-Posting-Host: bstfirewall.bst.bls.com
  10. In-reply-to: smelly@e-tex.com's message of Wed, 17 Jan 1996 23:29:44 -0600
  11.  
  12. In article <30FDDAC8.D79@e-tex.com> smelly@e-tex.com writes:
  13.  
  14. : I am also new to C programming; however, I think I can make one 
  15. : suggestion.  Since your second for loop does all the work and you don't 
  16. : need a body, you can write it like this.
  17.  
  18. :                for ( ; i<length, ((string[i]!='\n') &&
  19. :                    (string[i]!='\t') &&
  20. :                    (string[i]!=' ')); i++);
  21.  
  22. Eeeek !
  23. I would serious suggest not putting the ';' on the end of the loop like the
  24. above because in the middle of code this can be hard to spot especially in
  25. conjunction with bad formatting.
  26.  
  27.     while (*s);
  28.         *p++ = *s++;
  29.     *p = '\0';
  30.  
  31. I would suggest
  32.  
  33.     for (; *s; *p++ = *s++)
  34.     ;
  35.     *p = '\0';
  36.  
  37. It's easier to spot.
  38.  
  39. Regards
  40.  
  41.    -A
  42. -- 
  43. | A.Champion                |
  44.